package com.nuanshui.heatedloan.middleware.msgcenter.bean;

import com.google.common.collect.Lists;
import com.nuanshui.framework.lang.SysStringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;

/**
 * 发送消息扩展参数的 载体对象
 *
 * @param
 * @author guohao
 * @date 2017年2月10日 上午10:57:43
 * @since $
 */
public class Model implements Serializable {

    public static String USER_PHONE = "USER_PHONE"; //推送的手机号码，如果有就直接用这个了

    public static String ORDER_NUM = "ORDER_NUM";//订单号的key

    public static String BIZ_TYPE = "BIZ_TYPE";//业务类型

    public static String BIZ_ID = "BIZ_ID";//业务id的key

    public static String MSG_TYPE = "MSG_TYPE";// 推送或者是短信的业务类型 @see MessageType

    public static String MSG_TYPE_NAME = "MSG_TYPE_NAME";// 推送或者是短信的业务类型 @see MessageType

    public static String MSG_ID = "MSG_ID";//消息标题的ID

    public static String MSG_TITLE = "MSG_TITLE";//消息标题的key

    public static String MSG_CONTENT = "MSG_CONTENT";//消息内容的key

    public static String CLIENT_TYPE = "CLIENT_TYPE"; //设备类型 android ios 等等

    public static String BIZ_USER_ID = "BIZ_USER_ID"; //生成消息的时候, 消息产生者的用户id
    public static String DST_USER_ID = "DST_USER_ID"; //目标id

    public static String MSG_PUSH_PARAMS = "MSG_PUSH_PARAMS";//客户端提示所需参数

    private HashMap<String, Object> params = new HashMap<String, Object>();

    private HashMap<String, Object> extData = new HashMap<String, Object>();

    public HashMap<String, Object> getExtData()
    {
        return extData;
    }

    public String getClientType() {
        return getExtDataAsString(CLIENT_TYPE);
    }

    public void setClientType(String clientType) {
        putExtParam(CLIENT_TYPE, clientType);
    }

    private List<String> userIds=Lists.newArrayList();

    private List<String> phones=Lists.newArrayList();

    public void addDstUserId(String userId) {
        this.userIds.add(userId);
    }

    public void addDstUserIds(List<String> userIds) {
        this.userIds.addAll(userIds);
    }

    public String getDstUserId() {
        if (userIds != null && userIds.size() > 0) return userIds.get(0);
        return null;
    }

    public List<String> getDstUserIds() {
        return userIds;
    }

    public void addPhones(List<String> phones) {
        this.phones.addAll(phones);
    }

    public void addPhone(String phone) {
        if(SysStringUtils.isNotEmpty((phone)))
        {
            this.phones.add(phone);
        }
    }

    public String getPhone() {
        if (phones != null && phones.size() > 0) return phones.get(0);
        return null;
    }

    public List<String> getPhones() {
        return phones;
    }

    public String getMsgId() {
        return getExtDataAsString(MSG_ID);
    }

    public void setMsgId(String id) {
        putExtParam(MSG_ID, id);
    }

    public String getMsgContent() {
        return getAsString(MSG_CONTENT);
    }

    public String getMsgTitle() {
        return getAsString(MSG_TITLE);
    }

    public void setMsgTitle(String title) {
        putParam(MSG_TITLE, title);
    }

    public void setMsgContent(String content) {
        putParam(MSG_CONTENT, content);
    }

    public Integer getMessageType() {
        return (Integer) params.get(MSG_TYPE);
    }

    public void setMessageType(Integer msgType) {
        putParam(MSG_TYPE, msgType);
    }

    /**
     * MessageType 这种类型
     *
     * @Author: Gonzo
     * @Date 2017/4/5下午4:53
     * @since 1.4.2
     */
    public void setMessageType(Integer msgType, String msgTypeName) {
        putParam(MSG_TYPE, msgType);
        this.setMsgTypeName(msgTypeName);
    }

    public String getMsgTypeName() {
        return (String) getAsString(MSG_TYPE_NAME);
    }

    /**
     * MessageType 这种类型
     *
     * @Author: Gonzo
     * @Date 2017/4/5下午4:53
     * @since 1.4.2
     */
    public void setMsgTypeName(String msgTypeName) {
        putParam(MSG_TYPE_NAME, msgTypeName);
    }

    /**
     * 设置消息产生者用户 id
     *
     * @Author: Gonzo
     * @Date 2017/4/5下午7:21
     * @since 1.4.2
     */
    public void setBizUserId(String bizUserId) {
        putExtParam(BIZ_USER_ID, bizUserId);
    }

    public String getBizUserId() {
        return getExtDataAsString(BIZ_USER_ID);
    }

    public void setBizId(String bizId) {
        putParam(BIZ_ID, bizId);
    }

    public String getBizId() {
        return this.getAsString(BIZ_ID);
    }

    public String getBizType() {
        return getExtDataAsString(Model.BIZ_TYPE);
    }

    public void setBizType(String bizType) {
        getExtData().put(Model.BIZ_TYPE,bizType);
    }

    public void addOrderNum(String orderNum) {
        putParam(ORDER_NUM, orderNum);
    }

    public String getOrderNum() {
        return this.getAsString(ORDER_NUM);
    }

    public String getPushParams() {
        return this.getAsString(MSG_PUSH_PARAMS);
    }

    public String getAsString(String key) {
        Object value = params.get(key);
        if (value == null) return null;
        return String.valueOf(value);
    }

    public void putParam(String key,Object obj) {
        if (obj != null)
            params.put(key, obj);
    }

    public HashMap<String, Object> getParams() {
        return params;
    }

    public void setParams(HashMap<String, Object> params)
    {
        this.params=params;
    }

    public String getExtDataAsString(String key) {
        Object value = extData.get(key);
        if (value == null) return null;
        return String.valueOf(value);
    }

    public void putExtParam(String key,Object obj)
    {
        extData.put(key,obj);
    }

}

